﻿using CleanArchitecture.Infrastructure;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace CleanArchitecture.Web
{
    public class Startup
	{
        //public Startup(IConfiguration config) => this.Configuration = config;
        #region Fields

        private readonly IConfiguration _configuration;
        private readonly IWebHostEnvironment _hostingEnvironment;

        #endregion

        #region Ctor

        public Startup(IConfiguration configuration, IWebHostEnvironment hostingEnvironment)
        {
            _configuration = configuration;
            _hostingEnvironment = hostingEnvironment;
        }

        #endregion
        public IServiceProvider ConfigureServices(IServiceCollection services)
		{
            return services.ConfigureApplicationServices(_configuration, _hostingEnvironment);
        }

		public void Configure(IApplicationBuilder app)
		{
            // using Microsoft.AspNetCore.HttpOverrides;
            //https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-3.1
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });
            app.ConfigureRequestPipeline();
        }
	}
}
